<?php
/*
Plugin Name: Limit Posts
Plugin URI: http://labitacora.net/comunBlog/limit-post.phps
Description: Limits the displayed text length on the index page entries and generates a link to a page to read the full content if its bigger than the selected maximum length. 
Usage: the_content_limit($max_charaters, $more_link)
Version: 1.1
Author: Alfonso Sanchez-Paus Diaz y Julian Simon de Castro
Author URI: http://labitacora.net/
License: GPL
Download URL: http://labitacora.net/comunBlog/limit-post.phps
Make: 
    In file index.php 
    replace the_content() 
    with the_content_limit(1000, "more")

This plugin has been modified by the author of the Proximity theme in order to avoid conflict with the original plugin, should the user already have it installed and activated.
The new usage is prox_content_limit(1000, "more")
New features include stipping out all tags except paragraph and anchor tags,
along with removing any more link text.
Nathan Rice
*/

function prox_content_limit($max_char, $more_link_text = '...', $stripteaser = 0, $more_file = '') {
    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
    

   if (strlen($_GET['p']) > 0) {
      echo $content;
      return;
   }
   if ($max_char == 0 ) {
       echo $content;
       return;
   }
   $content = strip_tags($content, '<a></a>');
   //get the page link
   $pos = preg_match('{<a([^>]*)>}',$content,$matches);
   if ($pos){
       $view_page = '<p>'.$matches[0].'View Full Article</a></p>';
       $content = preg_replace('{(<a)([^<]*)(</a>)}','',$content);  //get rid of links
   }
   if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
        $content = substr($content, 0, $espacio);
        $content = $content.$view_page;
        echo $content;
   }
   else {
      echo $content.$view_page;
   }
}
?>